package com.weixing.mall.provider.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.weixing.mall.provider.mapper.LeaderShowMapper;
import com.weixing.mall.provider.model.enums.ads.PlatformTypeEunm;
import com.weixing.mall.provider.model.query.LeaderAdsQuery;
import com.weixing.mall.provider.service.ILeaderReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class LeaderReportService implements ILeaderReportService {
    @Autowired
    private LeaderShowMapper leaderShowMapper;

    @Override
    public Map<String, Object> personalAdsReport(LeaderAdsQuery laq) {
        return leaderShowMapper.personalAdsReport(laq);
    }

    @Override
    public Map<String, Object> teamAdsReport(LeaderAdsQuery laq) {
        return leaderShowMapper.teamAdsReport(laq);
    }

    @Override
    public IPage<Map<String, Object>> personalAdsReportList(Page page, LeaderAdsQuery laq) {
        IPage<Map<String, Object>> list = leaderShowMapper.personalAdsReportList(page,laq);
        addPlateformTypeName(list);
        addSerialNum(page,list);
        return list;
    }

    private IPage<Map<String, Object>> addSerialNum(Page page,IPage<Map<String, Object>> list){
        int i=1;
        for (Map<String, Object> m:list.getRecords()){
            //计算序号  序号等于 （页数-1）*10+i
            m.put("serialNum",(page.getCurrent()-1)*10 + i);
            i++;
        }
        return list;
    }

    @Override
    public IPage<Map<String, Object>> teamAdsReportList(Page page, LeaderAdsQuery laq) {
        IPage<Map<String, Object>> list = leaderShowMapper.teamAdsReportList(page, laq);
        addPlateformTypeName(list);
        addSerialNum(page,list);
        return list;
    }

    @Override
    public IPage<Map<String, Object>> getReportPresonlist(Page initMpPage, LeaderAdsQuery lsq) {
        return leaderShowMapper.getReportPresonlist(initMpPage,lsq);
    }

    private void addPlateformTypeName(IPage<Map<String, Object>> list){
        if(list.getRecords() != null && list.getRecords().size() > 0){
            list.getRecords().forEach(map -> {
                if(map.get("plateformType") != null && PlatformTypeEunm.WECHAT.getValue().equals(map.get("plateformType"))){
                    map.put("plateformTypeName",PlatformTypeEunm.WECHAT.getDesp());
                }else if(map.get("plateformType") != null && PlatformTypeEunm.CHATNUM.getValue().equals(map.get("plateformType"))){
                    map.put("plateformTypeName",PlatformTypeEunm.CHATNUM.getDesp());
                }else if(map.get("plateformType") != null && PlatformTypeEunm.TIKTOK.getValue().equals(map.get("plateformType"))){
                    map.put("plateformTypeName",PlatformTypeEunm.TIKTOK.getDesp());
                }else{
                    map.put("plateformTypeName","未知");
                }
            });
        }
    }
}

